angular.module('Controller')
.controller('QgyCleaningOrderDealCtrl',($scope,urls,$localStorage,NgTableParams,commonUtil,cryptUtil,wfAlert,commonConstant,$http, $uibModalInstance, items)->
    $scope.type=type=items.type
    $scope.data=data=items.data
    $scope.modalTitle=if type=='deal' then '保洁订单处理' else '保洁订单详情'
    $scope.modalEnableList=commonConstant.enabledList()
    $scope.qgyGoodStatusList=commonConstant.qgyGoodStatusList()
    theList=commonConstant.qgyCleaningOrderStatusList()
    $scope.cleaningDealStatusList=_.filter(theList,(theItem)->theItem.value in [3,5])
    if type=='deal' and data['serviceTime']==undefined
        data['serviceTime']=new Date()
        console.log(data.serviceTime)
    else
        data['serviceTime']=new Date(data['serviceTime'])
    _.extend $scope,
        dealData:()->
            reqData={
                "status":data.status
#                "customerRemark":data.customerRemark
                "remark":data.remark
            }
            reqData['serviceTime']=moment(data['serviceTime']).format('YYYY-MM-DD HH:mm:ss') if data['serviceTime']
            $http.put("/order/#{$scope.data.id}",reqData)
            .success((resp)->
                if resp.code==0
                    wfAlert.toastInfo($scope.modalTitle+'成功')
                    $uibModalInstance.close('done')
                else
                    wfAlert.toastError(resp.message)
            )
    $scope.confirm = ()->
        if type=='deal'
            $scope.dealData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')
)